package com.hxy.pet.controller;

import com.hxy.basic.exception.BusinessExcpetion;
import com.hxy.basic.query.util.AjaxResult;
import com.hxy.basic.query.util.PageList;
import com.hxy.pet.domain.Pet;
import com.hxy.pet.domain.SearchMasterMsg;
import com.hxy.pet.query.SearchMasterMsgQuery;
import com.hxy.pet.service.ISearchMasterMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 寻主消息Controller
 */
@Api(tags = "寻主接口",description = "寻主接口详细描述")
@RestController
@RequestMapping("/searchMasterMsg")
public class SearchMasterMsgController {

    @Autowired
    private ISearchMasterMsgService searchMasterMsgService;

    //获取所有对象：get
    //Get http://localhost:8080/searchMasterMsg
    @ApiOperation(value = "查询所有",notes = "不需参数")
    @GetMapping
    public List<SearchMasterMsg> getAll(){
        return searchMasterMsgService.getAll();
    }

    //发布寻主消息
    @ApiOperation(value = "发布寻主消息",notes = "")
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody SearchMasterMsg searchMasterMsg, HttpServletRequest request){
        try {

            searchMasterMsgService.publish(searchMasterMsg,request);
            return AjaxResult.me();
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("发布失败!" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误，稍后重试!!!");
        }
    }

    /**
     * 查询待处理的寻主消息 - 后台系统
     * @param searchMasterMsgQuery - 分页参数 + 高级查询参数
     * @return 查询结果 - totals data
     */
    @ApiOperation(value = "待处理的寻主消息",notes = "")
    @PostMapping("/pending")
    public PageList<SearchMasterMsg> pending(@RequestBody SearchMasterMsgQuery searchMasterMsgQuery,HttpServletRequest request){
        return searchMasterMsgService.pending(searchMasterMsgQuery,request);
    }


    /**
     * 查询已处理的寻主消息 - 后台系统
     * @param searchMasterMsgQuery - 分页参数 + 高级查询参数
     * @return 查询结果 - totals data
     */
    @ApiOperation(value = "已处理的寻主消息",notes = "")
    @PostMapping("/processed")
    public PageList<SearchMasterMsg> processed(@RequestBody SearchMasterMsgQuery searchMasterMsgQuery,HttpServletRequest request){
        return searchMasterMsgService.processed(searchMasterMsgQuery,request);
    }


    /**
     * 查询用户的寻主消息 - 前台系统 - 个人中心
     * @param searchMasterMsgQuery - 分页参数 + 高级查询参数
     * @return 查询结果 - totals data
     */
    @ApiOperation(value = "查询用户的寻主消息",notes = "")
    @PostMapping("/user")
    public PageList<SearchMasterMsg> user(@RequestBody SearchMasterMsgQuery searchMasterMsgQuery,HttpServletRequest request){
        return searchMasterMsgService.user(searchMasterMsgQuery,request);
    }

    /**
     * 处理寻主消息
     * @param pet
     * @return
     */
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody Pet pet, HttpServletRequest request){
        try {
            searchMasterMsgService.handle(pet,request);
            return new AjaxResult();
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("处理失败，" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统错误，" + e.getMessage());
        }
    }

}
